﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace BLL.SystemInformation
{
    [ServiceContract]
    public class UC_StationManage
    {
        DAL.DALMethod myDAL = new DAL.DALMethod();
        #region  站点信息
        [OperationContract]
        //查询站点信息
        public DataSet SelectStationManage()
        {
            SqlParameter[] SQLCMDpas ={
                new  SqlParameter ("@Type",SqlDbType.VarChar),
                    };
            SQLCMDpas[0].Value = "UserControl_Loaded_SelectStationManage";
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", SQLCMDpas);
            return myDataSet;
        }
        #endregion
        //查询邻居站点
        [OperationContract]
        public DataSet SelectSiteBySiteId(int intsite_id)
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("siteID",SqlDbType.Int)
            };
            parm[0].Value = "UserControl_Loaded_SelectSite_FromSiteId";
            parm[1].Value = intsite_id;
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", parm);
            return myDataSet;
        }
        //查询省份表
        [OperationContract]
        public DataSet SelectProvince()
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
            };
            parm[0].Value = "UserControl_Loaded_SelectProvince";
            DataSet myProvince = myDAL.QueryDataSet("UCStationManage", parm);
            return myProvince;
        }
        // 新增站点信息
        [OperationContract]
        public DataSet InsertStation(string siteName, string shortCode, string fullCode, int proID, bool stopOrNot)
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@siteName",SqlDbType.VarChar),
                new SqlParameter("@shortCode",SqlDbType.VarChar),
                new SqlParameter("@fullCode",SqlDbType.VarChar),
                new SqlParameter("@proID",SqlDbType.Int),
                new SqlParameter("@stopOrNot",SqlDbType.Bit)
            };
            parm[0].Value = "UserControl_Loaded_InsertStation";
            parm[1].Value = siteName;
            parm[2].Value = shortCode;
            parm[3].Value = fullCode;
            parm[4].Value = proID;
            parm[5].Value = stopOrNot;
            DataSet dataSet = myDAL.QueryDataSet("UCStationManage", parm);
            return dataSet;
        }
        // 新增邻居站点信息
        [OperationContract]
        public int InsertNeighborSite(int siteID, int neighborSiteID, decimal distance)
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@siteID",SqlDbType.Int),
                new SqlParameter("@neighborSiteID",SqlDbType.Int),
                new SqlParameter("@distance",SqlDbType.Decimal),
            };
            parm[0].Value = "UserControl_Loaded_InsertNeighborSite";
            parm[1].Value = siteID;
            parm[2].Value = neighborSiteID;
            parm[3].Value = distance;
            int count = myDAL.UpdateData("UCStationManage", parm);
            return count;
        }
        #region 修改信息
        [OperationContract]
        //查询站点信息（不包含自身）数据回填
        public DataSet USelectStationManage(int intsiteID)
        {
            SqlParameter[] SQLCMDpas ={
                    new  SqlParameter ("@Type",SqlDbType.VarChar),
                    new  SqlParameter ("@siteID",SqlDbType.Int),
                    };
            SQLCMDpas[0].Value = "UserControl_Loaded_USelectStationManage";
            SQLCMDpas[1].Value = intsiteID;
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", SQLCMDpas);
            return myDataSet;
        }
        //新增操作
        [OperationContract]
        public int UpdateStation(string siteName, string shortCode,string fullCode,int proID,bool stopOrNot,int siteID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@siteName",SqlDbType.Char),
                                          new  SqlParameter ("@shortCode",SqlDbType.Char),
                                          new  SqlParameter ("@fullCode",SqlDbType.Char),
                                          new  SqlParameter ("@proID",SqlDbType.Int),
                                          new  SqlParameter ("@stopOrNot",SqlDbType.Bit),
                                          new  SqlParameter ("@siteID",SqlDbType.Int)
                                                  };
            SQLCMDpas[0].Value = "UserControl_Loaded_UpdateStation";
            SQLCMDpas[1].Value = siteName;
            SQLCMDpas[2].Value = shortCode;
            SQLCMDpas[3].Value = fullCode;
            SQLCMDpas[4].Value = proID;
            SQLCMDpas[5].Value = stopOrNot;
            SQLCMDpas[6].Value = siteID;
            int count = myDAL.UpdateData("UCStationManage", SQLCMDpas);
            return count;
        }
        //删除邻居站点信息
        [OperationContract]
        public int DeleteNeighborSite(int neighborSiteID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@siteNeighborID",SqlDbType.Int),
                                                  };
            SQLCMDpas[0].Value = "UserControl_Loaded_DeleteNeighborSite";
            SQLCMDpas[1].Value = neighborSiteID;
            int count = myDAL.UpdateData("UCStationManage", SQLCMDpas);
            return count;
        }
        #endregion
        [OperationContract]
        // 删除站点信息
        public int DeleteStation(int siteID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@siteID",SqlDbType.Int)
                                                  };
            SQLCMDpas[0].Value = "UserControl_Loaded_DeleteStation";
            SQLCMDpas[1].Value = siteID;
            int count = myDAL.UpdateData("UCStationManage", SQLCMDpas);
            return count;
        }
        [OperationContract]
        // 停用站点信息
        public int StopSite(int siteID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@siteID",SqlDbType.Int)
                                                  };
            SQLCMDpas[0].Value = "UserControl_Loaded_StopSite";
            SQLCMDpas[1].Value = siteID;
            int count = myDAL.UpdateData("UCStationManage", SQLCMDpas);
            return count;
        }
        #region 线路信息
        [OperationContract]
        //查询站点信息(下拉框)
        public DataSet SelectStation()
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                              };
            SQLCMDpas[0].Value = "UserControl_Loaded_SelectStation";
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", SQLCMDpas);
            return myDataSet;
        }
        //查询线路
        [OperationContract]
        public DataSet SelectLine()
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                              };
            SQLCMDpas[0].Value = "UserControl_Loaded_SelectLine";
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", SQLCMDpas);
            return myDataSet;
        }
        //线路明细
        [OperationContract]
        public DataSet SelectDetailLine(int intLineID)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter("@lineID",SqlDbType.Int),
                                              };
            SQLCMDpas[0].Value = "UserControl_Loaded_SelectDetailLine";
            SQLCMDpas[1].Value = intLineID;
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", SQLCMDpas);
            return myDataSet;
        }
        //查询邻居站点信息
        [OperationContract]
        public DataSet SelectSite()
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char)
                                              };
            SQLCMDpas[0].Value = "UserControl_Loaded_SelectSite";
            DataSet myDataSet = myDAL.QueryDataSet("UCStationManage", SQLCMDpas);
            return myDataSet;
        }
        /// <summary>
        /// 新增线路信息
        /// </summary>
        [OperationContract]
        public DataSet InsertLine(string strLineName,string strSimpleCode,string strMileage,bool blStopNo,string strNote)
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@lineName",SqlDbType.VarChar),
                new SqlParameter("@simpleCode",SqlDbType.VarChar),
                new SqlParameter("@mileage",SqlDbType.VarChar),
                new SqlParameter("@stopNo",SqlDbType.Bit),
                new SqlParameter("@note",SqlDbType.VarChar)
            };
            parm[0].Value = "UserControl_Loaded_InsertLine";
            parm[1].Value = strLineName;
            parm[2].Value = strLineName;
            parm[3].Value = strMileage;
            parm[4].Value = blStopNo;
            parm[5].Value = strNote;
            DataSet data = myDAL.QueryDataSet("UCStationManage", parm);
            return data;
        }
        /// <summary>
        /// 新增明细线路信息
        /// </summary>
        [OperationContract]
        public int InsertDetailLine(int lineID, int siteID, int rankingSiteaID, decimal distance)
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@lineID",SqlDbType.Int),
                new SqlParameter("@siteID",SqlDbType.Int),
                new SqlParameter("@rankingSiteaID",SqlDbType.Int),
                new SqlParameter("@distance",SqlDbType.Decimal)
            };
            parm[0].Value = "UserControl_Loaded_InsertDetailLine";
            parm[1].Value = lineID;
            parm[2].Value = siteID;
            parm[3].Value = rankingSiteaID;
            parm[4].Value = distance;
            int  data = myDAL.UpdateData("UCStationManage", parm);
            return data;
        }
        /// <summary>
        /// 删除线路
        /// </summary>
        [OperationContract]
        public int DeleteLine(int lineID)
        {
            SqlParameter[] parm =
            {
                new SqlParameter("@type",SqlDbType.VarChar),
                new SqlParameter("@lineID",SqlDbType.Int)
            };
            parm[0].Value = "UserControl_Loaded_DeleteLine";
            parm[1].Value = lineID;
            int count = myDAL.UpdateData("UCStationManage", parm);
            return count;
        }
        /// <summary>
        /// 删除线路明细
        /// </summary>
        [OperationContract]
        public int DeleteDetailLine(int intDetailedLineId)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                          new  SqlParameter ("@detailedLineID",SqlDbType.Int),
                                              };
            SQLCMDpas[0].Value = "UserControl_Loaded_DeleteDetailLine";
            SQLCMDpas[1].Value = intDetailedLineId;
            int count = myDAL.UpdateData("UCStationManage", SQLCMDpas);
            return count;
        }
        [OperationContract]
        /// <summary>
        /// 停用线路
        /// </summary>
        /// <param name="blstop_no"></param>
        /// <param name="intline_id"></param>
        /// <returns></returns>
        public int UpdateLine(bool blStopNo, int intLineId)
        {
            SqlParameter[] SQLCMDpas ={
                                          new  SqlParameter ("@Type",SqlDbType.Char),
                                           new  SqlParameter ("@stopNo",SqlDbType.Bit),
                                          new  SqlParameter ("@lineID",SqlDbType.Int),
                                              };
            SQLCMDpas[0].Value = "UserControl_Loaded_UpdateLine";
            SQLCMDpas[1].Value = blStopNo;
            SQLCMDpas[2].Value = intLineId;
            int count = myDAL.UpdateData("UCStationManage", SQLCMDpas);
            return count;
        }
        #endregion

    }
}
